package com.jmxcfc.blfsc.ssq.service.contract.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jmxcfc.blfsc.ssq.entity.LockContractSub;
import com.jmxcfc.blfsc.ssq.mapper.LockContractSubMapper;
import com.jmxcfc.blfsc.ssq.service.contract.ILockContractSubService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 上上签锁定并结束合同记录表 服务实现类
 * </p>
 *
 * @author pbs
 * @since 2024-09-08
 */
@Service
public class LockContractSubServiceImpl extends ServiceImpl<LockContractSubMapper, LockContractSub> implements ILockContractSubService {

    @Override
    public String queryLatestContractId(String requestNo) {
        LambdaQueryWrapper<LockContractSub> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(LockContractSub::getContractId)
                .eq(LockContractSub::getRequestNo, requestNo)
                .eq(LockContractSub::getErrno, "0")
                .orderByDesc(LockContractSub::getCreateTime);
        List<LockContractSub> lockContractSubList = this.list(queryWrapper);
        String contractId = "";
        if (CollectionUtils.isNotEmpty(lockContractSubList) && StringUtils.isNotBlank(lockContractSubList.get(0).getContractId())) {
            contractId =  lockContractSubList.get(0).getContractId();
        }
        return contractId;
    }
}
